int str_match(const char* str, const char* match);
-char* strsub(const char* s, const char* search, const char* replace);
-char* gstrsub(const char* s, const char* search, const char* replace);
-
void rtrim(char* s);
char* lrtrim(char* buff);
int xasprintf(char** strp, const char* fmt, ...) PRINTFLIKE(2, 3);
info->track_path = nullptr;
info->waypoint_path = nullptr;
- char* s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder"));
- if (s) {
- s = gstrsub(s, "\\", "/");
- xasprintf(&info->waypoint_path, "%s/%s", path, s);
+ QString s = inifile_readstr(inifile, "UGDS", "WpFolder");
+ if (!s.isNull()) {
+ s.replace('\\', '/');
+ xasprintf(&info->waypoint_path, "%s/%s", path, CSTR(s));
}
- s = xstrdup(inifile_readstr(inifile, "UGDS", "GcFolder"));
- if (s) {
- s = gstrsub(s, "\\", "/");
- xasprintf(&info->geo_path, "%s/%s", path, s);
+ s = inifile_readstr(inifile, "UGDS", "GcFolder");
+ if (!s.isNull()) {
+ s.replace('\\', '/');
+ xasprintf(&info->geo_path, "%s/%s", path, CSTR(s));
}
- s = xstrdup(inifile_readstr(inifile, "UGDS", "TrkFolder"));
- if (s) {
- s = gstrsub(s, "\\", "/");
- xasprintf(&info->track_path, "%s/%s", path, s);
+ s = inifile_readstr(inifile, "UGDS", "TrkFolder");
+ if (!s.isNull()) {
+ s.replace('\\', '/');
+ xasprintf(&info->track_path, "%s/%s", path, CSTR(s));
}
inifile_done(inifile);
return (deg * 100.0) + ((deg_val - deg) * 60.0);
}
-/*
- * replace a single occurrence of "search" in "s" with "replace".
- * Returns an allocated copy if substitution was made, otherwise returns NULL.
- * Doesn't try to make an optimally sized dest buffer.
- */
-char*
-strsub(const char* s, const char* search, const char* replace)
-{
- int len = strlen(s);
- int slen = strlen(search);
- int rlen = strlen(replace);
-
- const char* p = strstr(s, search);
- if (!slen || !p) {
- return nullptr;
- }
-
- char* d = (char*) xmalloc(len + rlen + 1);
-
- /* Copy first part */
- len = p - s;
- memcpy(d, s, len);
- d[len] = 0;
-
- /* Copy replacement */
- strcat(d, replace);
-
- /* Copy last part */
- strcat(d, p + slen);
- return d;
-}
-
-/*
- * As strsub, but do it globally.
- */
-char*
-gstrsub(const char* s, const char* search, const char* replace)
-{
- int ooffs = 0;
- const char* c;
- const char* src = s;
- int olen = strlen(src);
- int slen = strlen(search);
- int rlen = strlen(replace);
-
- char* o = (char*) xmalloc(olen + 1);
-
- while ((c = strstr(src, search))) {
- olen += (rlen - slen);
- o = (char*) xrealloc(o, olen + 1);
- memcpy(o + ooffs, src, c - src);
- ooffs += (c - src);
- src = c + slen;
- if (rlen) {
- memcpy(o + ooffs, replace, rlen);
- ooffs += rlen;
- }
- }
-
- if (ooffs < olen) {
- memcpy(o + ooffs, src, olen - ooffs);
- }
- o[olen] = '\0';
- return o;
-}
-
/*
*
*/